package DigitalNetwork;

import java.awt.Color;
import java.awt.Graphics;

public class OscilloscopeView extends UnitView {

    /** [Konstruktor]
     * Hozzaadja a Unitot a View-hoz.
     */
	//==========================================================================
    public OscilloscopeView(Unit u){
        super(u);
    }
    //==========================================================================

	/**
	 * 
	 * @param g
	 * @return 
	 */
    @Override
	public void draw(Graphics g) {
		// A tartalmazott Unit kasztolasa Oscilloscope-ra
        Oscilloscope o = (Oscilloscope)this.unit;

        // Keret es UnitID szine
        g.setColor(Color.BLACK);

        // Keret kirajzolasa
        g.drawRoundRect(0, 0, NetworkView.UNIT_SIZE+20, NetworkView.UNIT_SIZE, 20, 20);
        g.drawString(this.unit.getID(), 2, NetworkView.UNIT_SIZE/2 - 15);
        g.drawString(this.unit.getType(), 2, NetworkView.UNIT_SIZE/2 );

        g.setColor(Color.GREEN);
        String s = "[";

        // Oscilloscope utolso 5 ertekenek kiirasa
        for(int i=o.getSignal().length-1; i>o.getSignal().length-6 && i>=0; i--){
            s = s + (o.getSignal()[i] ? "1" : "0");
        }
        s = s + "]";

        // Button ertekenek kirajzolasa
        g.drawString(s, 5, NetworkView.UNIT_SIZE/2 + 20 );
	}

}